package com.imooc.distributedemo.controller;

import lombok.extern.slf4j.Slf4j;

@Slf4j
//@RestController
public class LockController {
/*
    @Resource
    private DistributeLockMapper distributeLockMapper;

    private Lock lock = new ReentrantLock();

    @GetMapping("singleLock2")
    public String singleLock2(){
        log.info("我进入了方法");
        lock.lock();
        log.info("我进入了锁");
        try{
            Thread.sleep(10000);
        }catch (Exception e){
            log.error("业务执行出错",e);
            e.printStackTrace();
        } finally {
            lock.unlock();
        }
        return "我执行完了";
    }

    @GetMapping("singleLock")
    @Transactional
    public String singleLock() throws Exception{
        log.info("进入了方法");
        DistributeLock distributeLock = distributeLockMapper.selectDistributeLock("demo");
        if(distributeLock==null){
            throw new Exception("查询不到相关锁数据");
        }
        log.info("我进入了锁");
        try{
            Thread.sleep(10000);
        }catch (InterruptedException e){
            log.error("线程错误",e);
        }
        log.info("进入了mysql方式悲观锁");

        return "我执行完了";
    }*/
}
